import 'package:flower/utils/my_colors.dart';
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';

class FlowerCategory extends StatelessWidget {
  final List<String> images = [
    'assets/images/login_bg.jpg',
    'assets/images/login_bg.jpg',
    'assets/images/login_bg.jpg',
  ];

  final List<String> titles = ['康乃馨', '向日葵', '月季']; // 对应的文字标题列表

  @override
  Widget build(BuildContext context) {
    return CarouselSlider.builder(
      itemCount: images.length,
      options: CarouselOptions(
        autoPlay: true,
        enlargeCenterPage: true,
        aspectRatio: 16 / 5,
        viewportFraction: 0.8,
      ),
      itemBuilder: (BuildContext context, int index, int realIndex) {
        double screenWidth = MediaQuery.of(context).size.width;
        double imageWidth = screenWidth * 0.8; // 图片宽度为屏幕宽度的五分之四
        double imageHeight = imageWidth / 3; // 图片高度为宽度的一半
        return Container(
          margin: EdgeInsets.all(0.0),
          child: Stack(
            children: <Widget>[
              Image.asset(
                images[index],
                fit: BoxFit.cover,
                width: imageWidth,
                height: imageHeight,
              ),
              Positioned(
                bottom: 10,
                left: 10,
                top: 20,
                child: Text(
                  titles[index],
                  style: TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                      color: MyColors.yellow),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}